using Assets.Scripts.GDK;
using System;
using UnityEngine;
using UnityEngine.UI;

namespace Brick
{
	public class ShopPanel : gdk_base_panel
	{
		public RectTransform content;

		public RectTransform CoinIcon;

		public Text coinText;

		public GameObject shopNode;

		public GameObject PackageNode;

		public ShopNovicePackage novicePackage;

		public ShopLimitPackage limitPackage;

		public Text shopText;

		public Text giftText;

		public ShopGiftItem[] gifts;

		private Action callback;

		public ShopAdItem adItem;

		public ShopNoAdItem noAdItem;

		public Toggle shopToggle;

		public Toggle packageToggle;

		public void OnData(Action _callback)
		{
			callback = _callback;
		}

		public override void OnStart()
		{
			setText();
			setContent();
			setPackages();
			if (GDK.ModuleManger.Module<ShopPanelModule>().GetPage() == 1)
			{
				OnChoicePackage();
				shopToggle.isOn = false;
				packageToggle.isOn = true;
			}
			else
			{
				OnChoiceShop();
				shopToggle.isOn = true;
				packageToggle.isOn = false;
			}
		}

		private void setText()
		{
			coinText.text = GameData.coin.ToString();
		}

		private void setPackages()
		{
			GameGiftModel[] gameGiftArray = GameData.gameGiftArray;
			int num = 0;
			foreach (GameGiftModel giftItem in gameGiftArray)
			{
				if (giftItem.itype == 1)
				{
					novicePackage.OnData(giftItem, delegate
					{
						int shopID3 = giftItem.shopID;
						string info3 = giftItem.info;
						string name3 = giftItem.name;
						/*SDKManager.ClickPay(shopID3, 1, info3, name3, gdk_stringPlus.string2float(giftItem.dollar), delegate(bool code)
						{
							if (!code)
							{
								gdk_game_manager.log("取消购买");
							}
							else
							{
								gdk_game_manager.log("购买成功");
								GameData.buyNewerGift = true;
								DayModel[] array3 = new DayModel[3];
								for (int l = 0; l < 3; l++)
								{
									array3[l] = new DayModel
									{
										rewardType = giftItem.rawdType[l],
										rewardCount = giftItem.rawdCount[l]
									};
								}
								GameManager.showRewardsAlert(array3);
								OnCheckGift();
							}
						});*/
					});
				}
				if (giftItem.itype == 2)
				{
					limitPackage.OnData(giftItem, delegate
					{
						int shopID2 = giftItem.shopID;
						string info2 = giftItem.info;
						string name2 = giftItem.name;
						/*SDKManager.ClickPay(shopID2, 1, info2, name2, gdk_stringPlus.string2float(giftItem.dollar), delegate(bool code)
						{
							if (!code)
							{
								gdk_game_manager.log("取消购买");
							}
							else
							{
								gdk_game_manager.log("购买成功");
								GameData.buyWeekGift = true;
								DayModel[] array2 = new DayModel[3];
								for (int k = 0; k < 3; k++)
								{
									array2[k] = new DayModel
									{
										rewardType = giftItem.rawdType[k],
										rewardCount = giftItem.rawdCount[k]
									};
								}
								GameManager.showRewardsAlert(array2);
								limitPackage.OnUIUpdate();
							}
						});*/
					});
				}
				if (giftItem.itype == 3)
				{
					gifts[num].OnData(giftItem, delegate
					{
						int shopID = giftItem.shopID;
						string info = giftItem.info;
						string name = giftItem.name;
						/*SDKManager.ClickPay(shopID, 1, info, name, gdk_stringPlus.string2float(giftItem.dollar), delegate(bool code)
						{
							if (!code)
							{
								gdk_game_manager.log("取消购买");
							}
							else
							{
								gdk_game_manager.log("购买成功");
								DayModel[] array = new DayModel[3];
								for (int j = 0; j < 3; j++)
								{
									array[j] = new DayModel
									{
										rewardType = giftItem.rawdType[j],
										rewardCount = giftItem.rawdCount[j]
									};
								}
								GameManager.showRewardsAlert(array);
							}
						});*/
					});
					num++;
				}
			}
			OnCheckGift();
		}

		private void OnCheckGift()
		{
			if (GDK.ModuleManger.Module<ShopPanelModule>().GetNewerTime().Days > 3)
			{
				GameData.buyNewerGift = true;
			}
			if (GDK.ModuleManger.Module<ShopPanelModule>().GetBuyNewerGift())
			{
				novicePackage.gameObject.SetActive(value: false);
				limitPackage.gameObject.SetActive(value: true);
			}
			else
			{
				novicePackage.gameObject.SetActive(value: true);
				limitPackage.gameObject.SetActive(value: false);
			}
		}

		private void setContent()
		{
			gdk_utils.removeAllChildren(content);
			GameShopModel[] gameShopArray = GameData.gameShopArray;
			for (int i = 0; i < gameShopArray.Length; i++)
			{
				GameShopModel gameShopModel = gameShopArray[i];
				if (gameShopModel.itype == 3)
				{
					adItem.OnData(gameShopModel, delegate
					{
					});
					if (!GameManager.getFuncOpen("shopad"))
					{
						adItem.gameObject.SetActive(value: false);
					}
					else
					{
						adItem.gameObject.SetActive(value: true);
					}
				}
				if (gameShopModel.itype == 2)
				{
					if (!GameManager.getFuncOpen("shopnoad"))
					{
						noAdItem.gameObject.SetActive(value: false);
					}
					else
					{
						noAdItem.gameObject.SetActive(value: true);
					}
					noAdItem.OnData(gameShopModel, delegate
					{
						int shopID = gameShopModel.shopID;
						string info2 = gameShopModel.info;
						string name2 = gameShopModel.name;
						/*SDKManager.ClickPay(shopID, 1, info2, name2, gdk_stringPlus.string2float(gameShopModel.dollar), delegate(bool code)
						{
							if (!code)
							{
								gdk_game_manager.log("取消购买");
							}
							else
							{
								gdk_game_manager.log("购买成功");
								GameData.closeAD = true;
								noAdItem.OnUIUpdate();
							}
						});*/
					});
				}
				if (gameShopModel.itype == 1)
				{
					GameObject gameObject = gdk_game_manager.loadPrefab(ItemID.ShopPanelItem);
					gameObject.transform.SetParent(content, worldPositionStays: false);
					int num = i;
					gameObject.GetComponent<ShopPanelItem>().OnData(gameShopModel, delegate
					{
						int _shopID = gameShopModel.shopID;
						string info = gameShopModel.info;
						string name = gameShopModel.name;
						/*SDKManager.ClickPay(_shopID, 1, info, name, gdk_stringPlus.string2float(gameShopModel.dollar), delegate(bool code)
						{
							if (!code)
							{
								gdk_game_manager.log("取消购买");
							}
							else
							{
								gdk_game_manager.log("购买成功");
								GameManager.showAddCoinAlert(gameShopModel.coin, 2);
								GameManager.addCoin(gameShopModel.coin);
								if (_shopID == 950)
								{
									GameData.closeAD = true;
								}
								setText();
							}
						});*/
					});
				}
			}
		}

		public void OnShowSettingClick()
		{
			gdk_game_manager.showSetting(SettingID.SETTING);
			gdk_game_manager.PlaySound(AudioID.click);
		}

		public void OncloseClick()
		{
			close();
			if (callback != null)
			{
				callback();
			}
		}

		public void OnShowSelectClick()
		{
			gdk_game_manager.PlaySound(AudioID.click);
			OncloseClick();
		}

		public void OnChoiceShop()
		{
			shopNode.SetActive(value: true);
			PackageNode.SetActive(value: false);
			shopText.color = Color.blue;
			giftText.color = Color.white;
		}

		public void OnChoicePackage()
		{
			shopNode.SetActive(value: false);
			PackageNode.SetActive(value: true);
			shopText.color = Color.white;
			giftText.color = Color.blue;
		}
	}
}

